using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using FreeFlow.Administration;
using FreeFlow.WinFormsControls.HelperClasses;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for VariableControl.
	/// </summary>
	public class VariableControl : AdminUserControl
	{
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox nameLabel;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox netTypeLabel;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox databaseTypeLabel;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.TextBox sizeLabel;
    private FreeFlowAdministrator.UIActionsControl uiActionsControl;
    private System.Windows.Forms.PictureBox pictureBox1;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public VariableControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

      UIActionList actions = new UIActionList();
      actions.Add("Delete", "Delete this variable", new ActionExecuteDelegate(DeleteVariable));
      uiActionsControl.Actions = actions;
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(VariableControl));
      this.label1 = new System.Windows.Forms.Label();
      this.nameLabel = new System.Windows.Forms.TextBox();
      this.label2 = new System.Windows.Forms.Label();
      this.netTypeLabel = new System.Windows.Forms.TextBox();
      this.label3 = new System.Windows.Forms.Label();
      this.databaseTypeLabel = new System.Windows.Forms.TextBox();
      this.label4 = new System.Windows.Forms.Label();
      this.sizeLabel = new System.Windows.Forms.TextBox();
      this.uiActionsControl = new FreeFlowAdministrator.UIActionsControl();
      this.pictureBox1 = new System.Windows.Forms.PictureBox();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
      this.SuspendLayout();
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(8, 8);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(40, 16);
      this.label1.TabIndex = 0;
      this.label1.Text = "Name:";
      // 
      // nameLabel
      // 
      this.nameLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.nameLabel.BorderStyle = System.Windows.Forms.BorderStyle.None;
      this.nameLabel.Location = new System.Drawing.Point(88, 8);
      this.nameLabel.Name = "nameLabel";
      this.nameLabel.ReadOnly = true;
      this.nameLabel.Size = new System.Drawing.Size(328, 13);
      this.nameLabel.TabIndex = 1;
      this.nameLabel.Text = "nameLabel";
      // 
      // label2
      // 
      this.label2.Location = new System.Drawing.Point(8, 24);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(72, 16);
      this.label2.TabIndex = 2;
      this.label2.Text = ".NET type:";
      // 
      // netTypeLabel
      // 
      this.netTypeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.netTypeLabel.BorderStyle = System.Windows.Forms.BorderStyle.None;
      this.netTypeLabel.Location = new System.Drawing.Point(88, 24);
      this.netTypeLabel.Name = "netTypeLabel";
      this.netTypeLabel.ReadOnly = true;
      this.netTypeLabel.Size = new System.Drawing.Size(328, 13);
      this.netTypeLabel.TabIndex = 3;
      this.netTypeLabel.Text = "netTypeLabel";
      // 
      // label3
      // 
      this.label3.Location = new System.Drawing.Point(8, 40);
      this.label3.Name = "label3";
      this.label3.Size = new System.Drawing.Size(80, 16);
      this.label3.TabIndex = 4;
      this.label3.Text = "Database type:";
      // 
      // databaseTypeLabel
      // 
      this.databaseTypeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.databaseTypeLabel.BorderStyle = System.Windows.Forms.BorderStyle.None;
      this.databaseTypeLabel.Location = new System.Drawing.Point(88, 40);
      this.databaseTypeLabel.Name = "databaseTypeLabel";
      this.databaseTypeLabel.ReadOnly = true;
      this.databaseTypeLabel.Size = new System.Drawing.Size(368, 13);
      this.databaseTypeLabel.TabIndex = 5;
      this.databaseTypeLabel.Text = "databaseTypeLabel";
      // 
      // label4
      // 
      this.label4.Location = new System.Drawing.Point(8, 56);
      this.label4.Name = "label4";
      this.label4.Size = new System.Drawing.Size(48, 16);
      this.label4.TabIndex = 6;
      this.label4.Text = "Size:";
      // 
      // sizeLabel
      // 
      this.sizeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.sizeLabel.BorderStyle = System.Windows.Forms.BorderStyle.None;
      this.sizeLabel.Location = new System.Drawing.Point(88, 56);
      this.sizeLabel.Name = "sizeLabel";
      this.sizeLabel.ReadOnly = true;
      this.sizeLabel.Size = new System.Drawing.Size(368, 13);
      this.sizeLabel.TabIndex = 7;
      this.sizeLabel.Text = "sizeLabel";
      // 
      // uiActionsControl
      // 
      this.uiActionsControl.Actions = null;
      this.uiActionsControl.Dock = System.Windows.Forms.DockStyle.Right;
      this.uiActionsControl.Location = new System.Drawing.Point(466, 0);
      this.uiActionsControl.Name = "uiActionsControl";
      this.uiActionsControl.Size = new System.Drawing.Size(150, 272);
      this.uiActionsControl.TabIndex = 8;
      // 
      // pictureBox1
      // 
      this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
      this.pictureBox1.Location = new System.Drawing.Point(424, 8);
      this.pictureBox1.Name = "pictureBox1";
      this.pictureBox1.Size = new System.Drawing.Size(32, 32);
      this.pictureBox1.TabIndex = 9;
      this.pictureBox1.TabStop = false;
      // 
      // VariableControl
      // 
      this.Controls.Add(this.pictureBox1);
      this.Controls.Add(this.uiActionsControl);
      this.Controls.Add(this.sizeLabel);
      this.Controls.Add(this.label4);
      this.Controls.Add(this.databaseTypeLabel);
      this.Controls.Add(this.label3);
      this.Controls.Add(this.netTypeLabel);
      this.Controls.Add(this.label2);
      this.Controls.Add(this.nameLabel);
      this.Controls.Add(this.label1);
      this.Name = "VariableControl";
      this.Size = new System.Drawing.Size(616, 272);
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
      this.ResumeLayout(false);
      this.PerformLayout();

    }
		#endregion

    private Column variable;
    public void LoadVariable(Column variable)
    {
      this.variable = variable;
      nameLabel.Text = variable.Name;
      netTypeLabel.Text = variable.Type.ToString();
      databaseTypeLabel.Text = variable.DatabaseType;
      sizeLabel.Text = variable.Size.ToString();
    }

    private string DeleteVariable()
    {
      if (MessageBox.Show("Delete this variable?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
      {
        using (new CursorHandler())
        {
          variable.Delete();
        }
        OnItemDeleted();
        Dispose();
      }
      return null;
    }
	}
}
